package com.ruoyi.web.controller.cems;

import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cems.domain.BmsEmergencyManualGroup;
import com.ruoyi.cems.service.IBmsEmergencyManualGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急手册目录Controller
 * 
 * @author ruoyi
 * @date 2024-08-14
 */
@Api(description = "应急手册目录")
@RestController
@RequestMapping("/cems/emergencyManualGroup")
public class BmsEmergencyManualGroupController extends BaseController
{
    @Autowired
    private IBmsEmergencyManualGroupService bmsEmergencyManualGroupService;

    /**
     * 查询应急手册目录列表
     */
    @ApiOperation(value = "查询应急手册目录列表")
    @GetMapping("/list")
    public TableDataInfo list(BmsEmergencyManualGroup bmsEmergencyManualGroup)
    {
        startPage();
        bmsEmergencyManualGroup.setUnitCode(getLoginUser().getUser().getUnit());
        List<BmsEmergencyManualGroup> list = bmsEmergencyManualGroupService.selectBmsEmergencyManualGroupList(bmsEmergencyManualGroup);
        return getDataTable(list);
    }

    /**
     * 导出应急手册目录列表
     */
    @ApiOperation(value = "导出应急手册目录列表")
    @Log(title = "应急手册目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmsEmergencyManualGroup bmsEmergencyManualGroup)
    {
        bmsEmergencyManualGroup.setUnitCode(getLoginUser().getUser().getUnit());
        List<BmsEmergencyManualGroup> list = bmsEmergencyManualGroupService.selectBmsEmergencyManualGroupList(bmsEmergencyManualGroup);
        ExcelUtil<BmsEmergencyManualGroup> util = new ExcelUtil<BmsEmergencyManualGroup>(BmsEmergencyManualGroup.class);
        util.exportExcel(response, list, "应急手册目录数据");
    }

    /**
     * 获取应急手册目录详细信息
     */
    @ApiOperation(value = "获取应急手册目录详细信息")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(bmsEmergencyManualGroupService.selectBmsEmergencyManualGroupByID(ID));
    }

    /**
     * 新增应急手册目录
     */
    @ApiOperation(value = "新增应急手册目录")
    @Log(title = "应急手册目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsEmergencyManualGroup bmsEmergencyManualGroup)
    {
        bmsEmergencyManualGroup.setID(UUID.randomUUID().toString().replace("-", ""));
        bmsEmergencyManualGroup.setCreatedBy(getUserId().toString());
        bmsEmergencyManualGroup.setCreatedTime(new Date());
        bmsEmergencyManualGroup.setUnitCode(getLoginUser().getUser().getUnit());
        return toAjax(bmsEmergencyManualGroupService.insertBmsEmergencyManualGroup(bmsEmergencyManualGroup));
    }

    /**
     * 修改应急手册目录
     */
    @ApiOperation(value = "修改应急手册目录")
    @Log(title = "应急手册目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsEmergencyManualGroup bmsEmergencyManualGroup)
    {
        return toAjax(bmsEmergencyManualGroupService.updateBmsEmergencyManualGroup(bmsEmergencyManualGroup));
    }

    /**
     * 删除应急手册目录
     */
    @ApiOperation(value = "删除应急手册目录")
    @Log(title = "应急手册目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(bmsEmergencyManualGroupService.deleteBmsEmergencyManualGroupByIDs(IDs));
    }
}
